package learn.mqtt.config;

import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqttConfig {


    private static final String MQTT_BROKER_URL = "tcp://192.168.31.134:1883";
    private static final String CLIENT_ID = "springboot-mqtt-01";

    @Bean
    public MqttClient mqttClient() throws MqttException {
        MqttClient client = new MqttClient(MQTT_BROKER_URL, CLIENT_ID);
        MqttConnectOptions options = new MqttConnectOptions();
        options.setCleanSession(true);
        options.setUserName("DoDayum");
        options.setPassword("DoDayum".toCharArray());
        client.connect(options);
        return client;
    }

}
